package com.jjj.springmvc.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jjj.springmvc.dao.UserDao;
import com.jjj.springmvc.model.User;
import com.jjj.springmvc.service.UserService;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
	
	@Autowired
	UserDao userDao;
	
	@Override
	public User findById(String id) {
		return userDao.findById(id);
	}
	public List findUsersName() {
		return userDao.findUsersName();
	}

	@Override
	public User findByName(String name) {
		return userDao.findUserByName(name);
	}

	@Override
	public void saveUser(User user) {
		userDao.save(user);
	}

	@Override
	public void updateUser(User user) {
		userDao.updateUser(user);
	}

	@Override
	public void deleteUserById(String id) {
		userDao.deleteUserById(id);

	}

	@Override
	public List<User> findAllUsers() {
		List<User> list = userDao.findAllUsers();
		if(list==null) {
			list = new ArrayList<User>();
		}
		return list;
	}

	@Override
	public void deleteAllUsers() {
		userDao.deleteAllUser();

	}

	@Override
	public boolean isUserExist(User user) {
		
		return findByName(user.getName())!=null;
	}

}
